/**
 * 
 */
package org.dragonfire.irc.messages;

/**
 * @author Darth Android
 * @date Oct 28, 2007
 */
public class ServerMessage extends Message {

	public static ServerMessage parseServerMessage(String msg) {
		ServerMessage smsg = new ServerMessage(Message.parseMessage(msg));
		String[] parts = smsg.getPrefix().split(":");
		smsg.setDestination(parts[0]);
		smsg.timeStamp = new Long(parts[1]);
		smsg.setPrefix(parts[2]);
		return smsg;
	}

	private String destination;
	private long timeStamp = System.nanoTime();

	/**
	 * @param prefix
	 * @param command
	 * @param params
	 */
	public ServerMessage(String destination, String prefix, String command, String... params) {
		super(prefix, command, params);
		this.destination = destination;
	}

	public ServerMessage(Message clone) {
		super(clone);
		if (clone instanceof ServerMessage) {
			ServerMessage sclone = (ServerMessage) clone;
			timeStamp = sclone.timeStamp;
			setDestination(sclone.getDestination());
		}
	}

	/**
	 * @return the destination
	 */
	public String getDestination() {
		return destination;
	}

	public long getTime() {
		return timeStamp;
	}

	public void adjustTime(long offset) {
		timeStamp += offset;
	}

	/**
	 * @param destination
	 *            the destination to set
	 */
	public void setDestination(String destination) {
		this.destination = destination;
	}

	public String toString() {
		return ":" + getDestination() + ":" + getTime() + super.toString();
	}

}
